package com.ganeshkrishnan.globald.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.ganeshkrishnan.globald.abstracts.BaseObject;

@Entity
public class MilResource extends BaseObject{
	private static final long serialVersionUID = 1L;
	private Long ID;
	public final int ARMY=0;
	public final int TANK=1;
	public final int AIR=2;
	public final int NAVY=3;
	public final int SPIES=4;
	public final int SUB=5;
	
	public final int TANK1=5;
	
	
	
	
	public final int TANK2=6;
	public final int TANK3=7;
	//Number of units
	private long MilAvailable;
	//Pointer to unit type
	private int unitType;
	//last upgraded time
	private Date resourceUpdated;

	private Person person;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getID() {
		return ID;
	}

	public void setID(Long iD) {
		ID = iD;
	}

	@ManyToOne
	@JoinColumn(name = "PersonID", referencedColumnName="ID")
	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}
	

	public int getUnitType() {
		return unitType;
	}

	public void setUnitType(int unitType) {
		this.unitType = unitType;
	}

	public long getMilAvailable() {
		return MilAvailable;
	}

	public void setMilAvailable(long milAvailable) {
		MilAvailable = milAvailable;
	}

	@Column(name = "ResUpDate")
	public Date getResourceUpdated() {
		return resourceUpdated;
	}

	public void setResourceUpdated(Date resourceUpdated) {
		this.resourceUpdated = resourceUpdated;
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof MilResource)) return false;
		return unitType==((MilResource)o).getUnitType();
	//	return (((MilResource) o).person.getId() == person.getId());
	}

	@Override
	public int hashCode() {
		int result;
		result = (int)(person != null ? person.hashCode() : 0);
		result = 31 * result + (ID != null ? ID.hashCode() : 0);
		return result;
	}

	@Override
	public String toString() {
		return "Military " + person.getId();
	}
}
